package com.shamar.blog.enums;

/**
 * 使用枚举表述常量数据字典
 */
public enum BlogContentStateEnum {

	PUBLISHED(1, "已发布"), DRAFT(2, "草稿"),DROP(-1,"已下架"),NO_BLOG(0,"没有这篇博文"),DATABASE_ERROR(3,"数据库错误"),SUCCESS(4,"操作成功"),NULL_CONTENT_INFO(5,"传入了空的信息");

	private int state;

	private String stateInfo;

	private BlogContentStateEnum(int state, String stateInfo) {
		this.state = state;
		this.stateInfo = stateInfo;
	}

	public int getState() {
		return state;
	}

	public String getStateInfo() {
		return stateInfo;
	}

	/**
	 * 依据传入的state返回相应的enum值
	 * @param index
	 * @return
	 */
	public static BlogContentStateEnum stateOf(int index) {
		for (BlogContentStateEnum state : values()) {
			if (state.getState() == index) {
				return state;
			}
		}
		return null;
	}

}